package com.shwread.android.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;

import com.shwread.android.qysw10000136.R;


public class HeaderImgDialog
        extends
        Dialog
        implements
        View.OnClickListener
{
	private View                      btnCamera, btnLocal;
	private Context                     context;
	
	private OnUserinfoMenuClickListener menuClickListener;
	
	public HeaderImgDialog(Context context, OnUserinfoMenuClickListener menuClickListener) {
		super(context, R.style.common_dialog);
		this.menuClickListener = menuClickListener;
		this.context = context;
		setCanceledOnTouchOutside(true);
		findViews();
		setListeners();
		getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
		getWindow().setGravity(Gravity.BOTTOM);
		getWindow().setWindowAnimations(android.R.style.Animation_InputMethod);
	}
	
	private void findViews() {
		View view = LayoutInflater.from(context).inflate(R.layout.userinfo_change_logo_dialog, null);
		btnCamera = view.findViewById(R.id.userinfo_dialog_camera);
		btnLocal = view.findViewById(R.id.userinfo_dialog_local);
	
		setContentView(view);
	}
	
	private void setListeners() {
		btnCamera.setOnClickListener(this);
		btnLocal.setOnClickListener(this);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_MENU)
		{
			this.dismiss();
		}
		return super.onKeyDown(keyCode, event);
	}
	
	@Override
	public void onClick(View v) {
		this.dismiss();
		switch (v.getId()) {
			case R.id.userinfo_dialog_camera:
				this.dismiss();
				menuClickListener.openCamera();
				break;
			case R.id.userinfo_dialog_local:
				this.dismiss();
				menuClickListener.openLocal();
				break;
		}
	}
	
	public interface OnUserinfoMenuClickListener
	{
		void openCamera();
		
		void openLocal();
	}
}
